package us.mooresr.geartrack.client.events;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.EventHandler;
import us.mooresr.geartrack.shared.model.Item;
import com.google.gwt.event.shared.HasHandlers;

public class ItemCreatedEvent extends
		GwtEvent<ItemCreatedEvent.ItemCreatedHandler> {

	public static Type<ItemCreatedHandler> TYPE = new Type<ItemCreatedHandler>();
	private Item newItem;

	public interface ItemCreatedHandler extends EventHandler {
		void onItemCreated(ItemCreatedEvent event);
	}

	public ItemCreatedEvent(Item newItem) {
		this.newItem = newItem;
	}

	public Item getNewItem() {
		return newItem;
	}

	@Override
	protected void dispatch(ItemCreatedHandler handler) {
		handler.onItemCreated(this);
	}

	@Override
	public Type<ItemCreatedHandler> getAssociatedType() {
		return TYPE;
	}

	public static Type<ItemCreatedHandler> getType() {
		return TYPE;
	}

	public static void fire(HasHandlers source, Item newItem) {
		source.fireEvent(new ItemCreatedEvent(newItem));
	}
}
